<?php
/**
 * Created by PhpStorm.
 * User: wodrow
 * Date: 2018/11/7
 * Time: 11:07
 */

namespace api\modules\other\controllers;


use wodrow\yii\rest\Controller;

class CreditController extends Controller
{
    /**
     * 获取成功的征信
     * @desc get/post
     * @param string $idno 身份证
     * @param string $bank_name 银行
     * @throws \yii\db\Exception
     * @return array
     * @return array list 征信列表
     */
    public function actionGetCreditForSuccess($idno, $bank_name)
    {
        $r = [];
        $sql = "SELECT 
FROM_UNIXTIME(bank_back_send_log.time) as send_at, 
relation, custname, idno,  bank.`name`, 
orderno, 
guarantee_company_user_id, 
custom.orderno as custom_orderno
FROM bank_back_send_log
LEFT JOIN credit_order_log ON serial_number = for_serial_number
LEFT JOIN credit_order ON credit_order.id = credit_order_id
LEFT JOIN bank ON bank_id = bank.id
LEFT JOIN custom ON custom_id = custom.id
WHERE idno='{$idno}' -- 作为参数
AND bank.`name` = '{$bank_name}' -- 作为参数
AND req_result = '001' 
ORDER BY field(relation, '本人', '配偶', '反担保', '担保人'), bank_back_send_log.time desc
LIMIT 0,1";
        $data = \Yii::$app->db->createCommand($sql)->query();
        $r['list'] = $data;
        return $r;
    }
}